package com.lxz.datasource.common;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

public class ResultModel implements Serializable {
    private static final long serialVersionUID = -2445273895966412540L;

    @JSONField(name = "errorcode")
    @JsonProperty("errorcode")
    private Integer errorCode;
    private String msg;
    private Object content;

    public ResultModel() {
    }

    public ResultModel(Integer errorCode, String msg, Object content) {
        this.errorCode = errorCode;
        this.msg = msg;
        this.content = content;
    }

    /**
     * 成功
     */
    public static ResultModel success() {
        return new ResultModel(ResultStatus.RESULT_STATUS_SUCCESS.getValue(), null, null);
    }

    public static ResultModel success(Object content) {
        return new ResultModel(ResultStatus.RESULT_STATUS_SUCCESS.getValue(), null, content);
    }

    public static ResultModel success(String msg, Object content) {
        return new ResultModel(ResultStatus.RESULT_STATUS_SUCCESS.getValue(), msg, content);
    }

    /**
     * 失败
     */
    public static ResultModel fail() {
        return new ResultModel(ResultStatus.RESULT_STATUS_FAILURE.getValue(), null, null);
    }

    public static ResultModel fail(String msg) {
        return new ResultModel(ResultStatus.RESULT_STATUS_FAILURE.getValue(), msg, null);
    }

    public static ResultModel fail(String msg, Object content) {
        return new ResultModel(ResultStatus.RESULT_STATUS_FAILURE.getValue(), msg, content);
    }

    /**
     * 系统错误
     */
    public static ResultModel error() {
        return new ResultModel(ResultStatus.RESULT_STATUS_EXCEPTION.getValue(), null, null);
    }

    public static ResultModel error(String msg) {
        return new ResultModel(ResultStatus.RESULT_STATUS_EXCEPTION.getValue(), msg, null);
    }

    public static ResultModel error(String msg, Object content) {
        return new ResultModel(ResultStatus.RESULT_STATUS_EXCEPTION.getValue(), msg, content);
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }
}
